<?php
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>

<style>

    #service-in .service-list .center >div span .log {
        display: inline-block;
        width: 29px;
        height: 27px;
        background: #faa552 url("<?= Yii::getAlias('@web/backend/img/service/record1.png') ?>") no-repeat center center;
        border-radius: 5px;
        vertical-align: bottom;
    }
    @media (min-width: 992px) and (max-width: 1440px){
         #service-in ul{
             display: flex;
             -webkit-flex-wrap:wrap;
             -webkit-box-lines:multiple;
             -moz-flex-wrap:wrap;
             flex-wrap:wrap;
         }
        #service-in .service-list{
            float: none;
            margin: 10px;

        }
        #service-in .service-list:nth-child(3n){margin-right: 10px;}
    }

</style>

<?= $this->render('header'); ?>
<?= $this->render('_sever'); ?>
<div id="service-in" class="container">
    <ul class="row">

        <?php foreach($list as $service): ?>
        <li class="service-list">
            <div class="top">
                <img aid="<?= $service['service_id'] ?>" class="head role" src="" alt="头像"/>
                <div>
                    <span class="name">
                        <?= $service['members']['member_name'] ?><?php if($service['members']['member_type'] == 1): ?><img src="<?= Yii::getAlias('@web/backend/img/service/crown.png') ?>" alt=""/><?php endif; ?></span>
                    <span class="phone"><?= $service['members']['member_mobile'] ?> </span>
                </div>
            </div>

            <?php
                $employee_name = []; // 服务师
                $beautycartd_name = []; // 服务项目
                foreach ($service['extends'] as $extend) {
                    $employee_name[] = $extend['employee_name'];
                    $beautycartd_name[] = $extend['beautycartd_name'];
                }
            ?>
            <div class="center clearfix">
                <div class="pull-left">
                    <span>
                        服务师：<?= implode('、', $employee_name) ?>
                    </span>
                    <span>到店时间：<?= str_replace('-', '.', substr($service['service_addtime'], 0, 16)) ?> </span>
                    <span>服务项目：<?= implode('、', $beautycartd_name) ?></span>

                    <a class="btns okBtn ml20" href="javascript:completeServer(<?= $service['service_id'] ?>)">完成服务</a>
                </div>
                <div class="pull-right">

                    <span>房间：<?= $service['room_name'] ?></span>
                    <span>已服务：<?= ($times = round((time() - strtotime($service['service_addtime'])) / 60)) < 1 ? '0' : $times ?>分钟</span>
                    <span>服务记录：<a class="log remark" durl="<?=Url::to(['remark', 'id' => $service['service_id'], 'u' => 'now'])?>" href="javascript:;"></a></span>
                    <a class="btns restBtn" href="javascript:cancelServer(<?= $service['service_id'] ?>)">取消服务</a>
                </div>
            </div>
        </li>
        <?php endforeach; ?>

    </ul>

    <div class="page">
        <?= LinkPager::widget([
            'pagination' => $page,
            // 'hideOnSinglePage' => true
        ]); ?>
    </div>

</div>

<script>
    <?php $this->beginBlock('js_index') ?>

    $(function(){
         var $severDate = document.getElementsByClassName('service-list')
         var $severRow = $('.sever-row')
        console.log($severDate)
        if ($severDate.length != '0'){
            $severRow.addClass("sever_none")
        }
        else {
            $severRow.removeClass('sever_none')
        }
    });

    $(function(){
        $('.role').each(function () {
            var $id =$(this).attr('aid');
            $(this).attr('src','/backend/img/member/ico'+($id%20+1)+'.png');
        });

        function openPage() {
            var obj = $(this);
            var url = obj.attr('durl');
            layer.open({
                type: 2,
                title: '',
                shadeClose: false,
                shade: 0.8,
                maxmin: true, //开启最大化最小化按钮
                area: ['40%', '410px'],
                content: url
            });
        }
        $('.remark').on('click', openPage);
    });

    // 完成服务
    function completeServer(service_id) {
        $.get("<?= Url::to(['changes']) ?>", {id:service_id, status:2}, function(status) {
//            alert(status);
            location.reload();
        });
    }
    /**
     * 取消服务
     * @param service_id 服务id
     */
    function cancelServer(service_id) {
        $.get("<?= Url::to(['changes']) ?>", {id:service_id, status:0}, function(status) {
            location.reload();
        });
    }

    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>
</script>